<?php
class Admin_Model_Package extends Core_Database
{
    /**
     * Lay danh sach tat ca cac goi dich vu
     * @param: void
     * @return : array(): neu co it nhat mot package  null: neu khong co package nao
     * 
     * */
    public function getPackages()
    {
     $sql = 'select * from package';
     $sth = $this->_db->prepare($sql);
     $status = $sth->execute();
     if (!$status)
          return null;
     $result = $sth->fetchAll();
     if(count($result)>0)
        return $result;
     else
        return null;   
    }
    
    /**
     * Them mot package moi
     * @param: package_name cpu ram os_name template_id pph
     * @return: bool  true: thanh cong, false : that bai
     * 
     * */
    public function insertPackage($package_name,$cpu,$ram,$os_name,$template_id,$pph)
    {
        $sql = 'insert into package(package_name,cpu,ram,os_name,template_id,pph) values(:package_name,:cpu,:ram,:os_name,:template_id,:pph)';
    	$sth = $this->_db->prepare($sql);
    	$sth->bindParam(':package_name', $package_name, PDO::PARAM_STR);
    	$sth->bindParam(':cpu', $cpu, PDO::PARAM_INT);
    	$sth->bindParam(':ram', $ram, PDO::PARAM_INT);
        $sth->bindParam(':os_name', $os_name, PDO::PARAM_STR);
        $sth->bindParam(':template_id', $template_id, PDO::PARAM_INT);
        $sth->bindParam(':pph', $pph, PDO::PARAM_INT);
    	return $sth->execute();
    }

    /**
     * Lay mot package
     * @param : package_id
     * @return : array : neu ton tai  null : neu khong ton tai
     * */
    public function getPackage($package_id)
    {
        $sql = 'select * from package where package_id = :package_id';
        $sth = $this->_db->prepare($sql);
        $sth->bindParam(':package_id',$package_id,PDO::PARAM_INT);
        $status = $sth->execute();
        if (!$status)
            return null;
        $result = $sth->fetchAll();
        if(count($result)>0)
           return $result;
        else
           return null;  
    }
    
    /**
     * Cap nhat package
     * @param : package_id  package_name cpu ram os_name template_id pph
     * @return bool true : thanh cong , false: that bai
     * */
     public function updatePackage($package_id,$package_name,$cpu,$ram,$os_name,$template_id,$pph)
     {
        $sql = 'update package set package_name = :package_name, cpu = :cpu, ram = :ram, os_name = :os_name, 
                template_id = :template_id, pph = :pph where package_id = :package_id';
    	$sth = $this->_db->prepare($sql);
    	$sth->bindParam(':package_id',$package_id,PDO::PARAM_INT);
  	    $sth->bindParam(':package_name', $package_name, PDO::PARAM_STR);
    	$sth->bindParam(':cpu', $cpu, PDO::PARAM_INT);
    	$sth->bindParam(':ram', $ram, PDO::PARAM_INT);
        $sth->bindParam(':os_name', $os_name, PDO::PARAM_STR);
        $sth->bindParam(':template_id', $template_id, PDO::PARAM_INT);
        $sth->bindParam(':pph', $pph, PDO::PARAM_INT);
    	return $sth->execute();
     }
     
     /**
      * Xoa mot package
      * @param :package_id
      * @return bool  true: thanh cong false: that bai
      * */
      public function deletePackage($package_id)
      {
        $sql = 'delete from package where package_id = :package_id';
        $sth = $this->_db->prepare($sql);
        $sth->bindParam(':package_id',$package_id,PDO::PARAM_INT);
        return $sth->execute();
      } 
   
}